<?php


namespace App\Model\Logic;


use App\Helper\RedisConst;
use App\Model\Entity\Country;
use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\Redis\Pool;

/**
 * @Bean()
 * Class CountryLogic
 * @package App\Model\Logic
 */
class CountryLogic
{

    /**
     * @Inject("redis1.pool")
     * @var Pool
     */
    private $redis;


    /**
     * 获取国家名
     * @param $nation_id
     * @return array|string|null
     */
    public function getName($nation_id)
    {
        if(!$nation_id) return "";
        $name = $this->redis->hGet(RedisConst::NATION. $nation_id, 'name');
        if($name) return $name;
        $nation = Country::find($nation_id);
        if($nation) return "";
        return $nation->getName();

    }


}